<meta charset="utf-8">
(#) Picture In Picture best practices not followed

!!! WARNING: Picture In Picture best practices not followed
   This is a warning.

Id
:   `PictureInPictureIssue`
Summary
:   Picture In Picture best practices not followed
Severity
:   Warning
Category
:   Correctness
Platform
:   Android
Vendor
:   Android Open Source Project
Feedback
:   https://issuetracker.google.com/issues/new?component=192708
Since
:   8.6.0 (August 2024)
Affects
:   Kotlin and Java files
Editing
:   This check can *not* run live in the IDE editor
See
:   https://developer.android.com/develop/ui/views/picture-in-picture#smoother-transition
Implementation
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/PictureInPictureDetector.kt)
Tests
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PictureInPictureDetectorTest.kt)

Starting in Android 12, the recommended approach for enabling
picture-in-picture (PiP) has changed. If your app does not use the new
approach, your app's transition animations will be of poor quality
compared to other apps. The new approach requires calling
`setAutoEnterEnabled(true)` and `setSourceRectHint(...)`.

(##) Example

Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
AndroidManifest.xml:9:Warning: An activity in this app supports
picture-in-picture and the targetSdkVersion is 31 or above; it is
therefore strongly recommended to call both setAutoEnterEnabled(true)
and setSourceRectHint(...) [PictureInPictureIssue]
    &lt;application
     -----------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here are the relevant source files:

`AndroidManifest.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;manifest
  package="test.pkg"
  xmlns:android="http://schemas.android.com/apk/res/android"&gt;

    &lt;uses-sdk
      android:minSdkVersion="28"
      android:targetSdkVersion="31" /&gt;

    &lt;application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"&gt;

        &lt;activity
            android:name=".TestActivity"
            android:exported="true"
            android:supportsPictureInPicture="true"
            android:configChanges="screenLayout|orientation|screenSize|smallestScreenSize"&gt;

            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;
                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;

        &lt;/activity&gt;

    &lt;/application&gt;

&lt;/manifest&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`src/test/pkg/TestActivity.kt`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers
package test.pkg

import android.app.Activity

class TestActivity: Activity {
  fun test() {
    enterPictureInPictureMode()
  }
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also visit the
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/PictureInPictureDetectorTest.kt)
for the unit tests for this check to see additional scenarios.

(##) Suppressing

You can suppress false positives using one of the following mechanisms:

* Using a special `lint.xml` file in the source tree which turns off
  the check in that folder and any sub folder. A simple file might look
  like this:
  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;lint&gt;
      &lt;issue id="PictureInPictureIssue" severity="ignore" /&gt;
  &lt;/lint&gt;
  ```
  Instead of `ignore` you can also change the severity here, for
  example from `error` to `warning`. You can find additional
  documentation on how to filter issues by path, regular expression and
  so on
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).

* In Gradle projects, using the DSL syntax to configure lint. For
  example, you can use something like
  ```gradle
  lintOptions {
      disable 'PictureInPictureIssue'
  }
  ```
  In Android projects this should be nested inside an `android { }`
  block.

* For manual invocations of `lint`, using the `--ignore` flag:
  ```
  $ lint --ignore PictureInPictureIssue ...`
  ```

* Last, but not least, using baselines, as discussed
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).

<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>